﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Configuration;

namespace Root.Models.BLL
{
    public class ConfigHelper : CollectionBase
    {
        public static ConfigHelper appSettings = new ConfigHelper();
        public string this[string key]
        {
            get
            {
                return ConfigurationManager.AppSettings[key];
            }
            set
            {
                if (ConfigurationManager.AppSettings[key] == null)
                {
                    Configuration config = WebConfigurationManager.OpenWebConfiguration(null); 
                    config.AppSettings.Settings.Add(key, value);
                    config.Save();
                }
                else
                {
                    Configuration config = WebConfigurationManager.OpenWebConfiguration(null);
                    config.AppSettings.Settings[key].Value = value;
                    config.Save();
                }
            }
        }
    }
}